#include Adafruit_NeoPixel.h // Pin connected to the NeoPixels (WS2812B) #define LED_PIN 15 // Number of NeoPixels #define LED_COUNT 1 // Create NeoPixel object Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); void setup() { // Initialize NeoPixel strip strip.begin(); strip.show(); // Initialize all pixels to 'off' } void loop() { // Cycle through different colors rainbow(20); // Change colors every 20ms } // Function to cycle through rainbow colors void rainbow(uint8_t wait) { for (uint16_t i = 0; i < 256; i++) { uint32_t color = Wheel((i + strip.numPixels()) & 255); for (int j = 0; j < strip.numPixels(); j++) { strip.setPixelColor(j, color); } strip.show(); delay(wait); } } // Input a value 0 to 255 to get a color value. // The colors are a transition r - g - b - back to r. uint32_t Wheel(byte WheelPos) { WheelPos = 255 - WheelPos; if (WheelPos < 85) { return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); } if (WheelPos < 170) { WheelPos -= 85; return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); } WheelPos -= 170; return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); }